#pragma once

#include "Protocol.hpp"
#include <iostream>
#include <string>

class Calculator
{
public:
    Calculator()
    {
    }
    Response Exec(Request &rq)
    {
        Response rp;
        switch (rq.Oper())
        {
        case '+':
            rp.SetResult(rq.X() + rq.Y());
            break;
        case '-':
            rp.SetResult(rq.X() - rq.Y());
            break;
        case '*':
            rp.SetResult(rq.X() * rq.Y());
            break;
        case '/':
        {
            if (rq.Y() == 0)
            {
                rp.SetCode(1);  // 1 -> /
            }
            else
            {
                rp.SetResult(rq.X() / rq.Y());
            }
        }
        break;
        case '%':
        {
            if (rq.Y() == 0)
            {
                rp.SetCode(2);  // 2 -> %
            }
            else
            {
                rp.SetResult(rq.X() % rq.Y());
            }
        }
        break;
        default:
            rp.SetCode(3);  // false
            break;
        }
        return rp;
    }
    ~Calculator()
    {
    }
};